package com.zhentao.controller;

import com.zhentao.login.service.TUserService;
import com.zhentao.nlz.project.login.TUser;
import com.zhentao.nlz.project.product.TUserInfo;
import com.zhentao.nlz.project.product.vo.UserVo;
import com.zhentao.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private TUserService userService;
    @GetMapping("getUser")
    public Result getUser(UserVo userVo){
        userVo.setPageNum(1);
        userVo.setPageSize(2);
        System.err.println(userVo);

        List<UserVo> list = userService.getUser(userVo);
        return Result.success(list);
    }
    //添加用户
    @PostMapping("saveUser")
    public Result saveUserInfo(TUser user) {
        user.setCreateTime(new Date());
        boolean b = userService.save(user);
        return Result.success(b);
    }
    //删除用户
    @PostMapping("removeUser/{userId}")
    public Result removeUserInfo(@PathVariable("userId") Integer userId){
        System.out.println("userId = " + userId);
        boolean b = userService.removeById(userId);
        return Result.success(b);
    }
    //修改用户信息
    @PostMapping("updateUser")
    public Result updateUserInfo(TUser user){

        boolean b = userService.updateUserInfo(user);
        return Result.success(b);
    }
}
